const express=require('express')

const users=express.Router()
const axios=require('axios')

//粉丝列表
users.get('/fan/fansList', (req, res) => {
    let { userId,pageNum,pageSize } = req.query
    if(req.session.userMessage==undefined){
        res.status(200).json({
            key:'请先登录'
        })
    }else{
        axios({
            method: 'get',
            url:'/user/fansList',
            params: {
                userId: userId||req.session.userMessage.id,
                pageNum: pageNum,
                pageSize: pageSize
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            }
        }).then(data=>{
            res.status(200).json({
                key:data.data 
            })
        }).catch(err=>{
            res.status(200).json({
                err:err
            })
        })
    }
})

//关注列表
users.get('/attaction/fansList', (req, res) => {
    let { userId,pageNum,pageSize } = req.query
    if(req.session.userMessage==undefined){
        res.status(200).json({
            key:'请先登录'
        })
    }else{
        axios({
            method: 'get',
            url:'/user/followeeList',
            params: {
                userId: userId||req.session.userMessage.id,
                pageNum: pageNum||5,
                pageSize: pageSize||1
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            }
        }).then(data=>{
            res.status(200).json({
                key:data.data 
            })
        }).catch(err=>{
            res.status(200).json({
                err:err
            })
        })
    }
})

//关注列表关注和取消关注
users.get('/attaction/folloUser',(req,res)=>{
    let {followeeId,userId} = req.query
    if(req.session.userMessage!=undefined||userId){
        axios({
            url:'/user/followeeUser',
            method:'post',
            params:{
                followeeId:followeeId,
                userId:userId||req.session.userMessage.id,
            }
        })
        .then(data=>{
            res.status(200).json({
                key:data.data 
            })
        })
        .catch(err=>{
            res.status(200).json({
                key:err
            })
        })
    }
})
module.exports=users